February 20, 2020
Here is the next set. I have posted screenshot for every single command so that you will catch up with right syntax. Let us start!
What would be the first command as soon as we open R Studio.. Yes!! It is rm(list=ls()) - Removing all objects stored in RAM. Now set current working Directory using setwd command. Now start working on commands…
We all know mtcars is a preloaded dataset. We are going to select few columns(variables) from the mtcars dataset. Now Commands below..
TempData = mtcars //assigning mtcars to object TempData
View(TempData) // Viewing TempData
TestData = subset(TempData, select = c(“hp”, “drat”)) //Selecting particular coulmns(variables) from TempData(mtcars)
View(TestData) //Viewing output
TestData1 = TempData[which(TempData$hp == 110),]
In Above Command, from TempData, we are selecting rows which has hp=110 value. As this is Row level operation we are leaving nothing after comma.
TestMatrix = matrix(11:19, byrow = T, nrow =3)
This command will arrange 11 to 19 by 3 rows. If we set byrow = F, it will arrange by column. We can also mention number of columns as ncol.
TestMatrix = matrix(11:19, byrow = T, nrow =3)
View(TestMatrix)
t(TestMatrix) // t for transpose
TestVector = c(11, 15, 18, 19)
Just wanted to explain the differnce between vector and matrix as i just browsed and understood, so that you dont need to waste your time on browsing to understand the same. Vector is a list of numbers and it can be either in row or column, whereas Matrix is an array of numbers with rows and columns.
Let us finish this page with above commands. There are more and more commands, i will update in my next blog post. Stay Tuned!